package com.tianze.tzkf.base;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by parry on 2017.03.22
 */
public abstract class BaseFragment extends Fragment {


    protected Context mContext = null;
    protected Activity mActivity = null;
    private Unbinder unbinder;


    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mContext = activity;
        mActivity = activity;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(getLayoutId(), container, false);
        unbinder = ButterKnife.bind(BaseFragment.this, view);
        initTitle();
        initData();
        return view;

    }

    @Override
    public void onResume() {
        super.onResume();

    }


    /**
     * 绑定布局
     * @return 布局ID
     */
    public abstract int getLayoutId();

    /**
     * 初始化标题
     */
    protected abstract void initTitle();

    /**
     * 初始化数据
     */
    protected abstract void initData();


    @Override
    public void onDestroy() {


        //        EventBus.getDefault().unregister(this);

        unbinder.unbind();
        super.onDestroy();
    }





}
